package com.robcity.platform.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 订单状态机
 * @author zhouwei
 */
@Getter
@AllArgsConstructor
public enum OrderStatusEnum {

    DEFAULT(0, "默认"),

    PAY_WAIT(10, "待支付"),

    SUCCESS(40, "已完成"),

    FAIL(90, "失败"),
    ;

    /**
     * 状态code
     */
    private final Integer code;

    /**
     * 状态描述
     */
    private final String desc;

    public static OrderStatusEnum getByCode(Integer code) {
        if (Objects.isNull(code)) {
            return null;
        }
        for (OrderStatusEnum type : OrderStatusEnum.values()) {
            if (Objects.equals(type.getCode(), code)) {
                return type;
            }
        }
        return null;
    }

}
